package cht;

import static org.junit.Assert.assertTrue;
import robocode.control.events.RoundEndedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IBulletSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * Tests to see whether bullet power increased upon hitting another robot.
 * 
 * @author Terrence Chida
 *
 */
public class TestNarchiPowerUp extends RobotTestBed {
  
  boolean fired = false;
  double power;
  boolean powerUp = false;

  /**
   * Specifies that SittingDuck and Narchi are being matched up in this test.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,cht.Narchi";
  }

  
  /**
   * This test runs for 10 round.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  
  /**
   * After each turn, check to see if we at least fired a bullet.
   * 
   * @param event Info about the current state of the battle.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    // Get the set of bullets fired until now.
    IBulletSnapshot bullets[] = event.getTurnSnapshot().getBullets();
    // Since SittingDuck doesn't fire, all bullets fired were from Narchi.
    if (bullets.length != 0) {
      this.fired = true;
      // Get the power of the latest bullet.
      // Bullet power begins as 1, so if any bullet has power greater than 1, it was powered up.
      this.power = bullets[bullets.length - 1].getPower();
      if (this.power > 1) {
        this.powerUp = true;
      }
    }
  } // end onTurnEnded()

  
  /**
   * After each round, make assertions on whether Narchi fired and powered up.
   * 
   * @param event Info about the current state of the battle.
   */
  @Override
  public void onRoundEnded(RoundEndedEvent event) {
    assertTrue("No bullets fired.", this.fired);
    assertTrue("Check bullet power.", this.powerUp);
  }

} // end TestNarchiPowerUp
